﻿using AsterNET.Extensions.FastAGI.Helpers;
using AsterNET.FastAGI;
using AsterNET.FastAGI.MappingStrategies;
using System;
using System.Collections.Generic;
using AGIScript = AsterNET.Extensions.FastAGI.AGIScript.AGIScript;

namespace Test.Application
{
	class Program
	{
		static void Main(string[] args)
		{
			// Load an instance of the FastAGI Server using the GeneralMappingStratagy
			AsteriskFastAGI agi = new AsteriskFastAGI();

			agi.BindPort = 8675;			// custom port for my firewall! Comment this out or change for your firewall
			agi.MappingStrategy = new GeneralMappingStrategy(new List<ScriptMapping>()
			{
				new AsterNET.FastAGI.MappingStrategies.ScriptMapping() {
					ScriptClass = "Test.Application.customivr",
					ScriptName = "customivr"
				},
			});

			agi.SCHANGUP_CAUSES_EXCEPTION = true;

			Console.WriteLine("Starting FastAGI Server");
			agi.Start();
	
		}
	}

	// Our main AGI
	public class customivr : AsterNET.FastAGI.AGIScript
	{
		public override void Service(AsterNET.FastAGI.AGIRequest request, AsterNET.FastAGI.AGIChannel channel)
		{
			Answer();

			// Method 1, using the Dial Helper class directly
			var dialReply = channel.SendCommand(DialHelper.Dial("SIP/100", 10000, null,
				DialOptions.AnnounceToCallee("demo-congrats")));

			Hangup();
		}
	}

	public class customivr2 : AGIScript
	{
		public override void Service(AsterNET.FastAGI.AGIRequest request, AsterNET.FastAGI.AGIChannel channel)
		{
			Answer();

			// Using Dial from extended agi class
			var rtn = Dial("SIP/100", 10000, null, DialOptions.AnnounceToCallee("demo-congrats"));
			Console.WriteLine(rtn);

			Wait(5);

			// Originate to peer in context default, extension 1234 and prio 1
			Originate("SIP/peer", OriginateType.Exten, "default", "1234", "1");

			Hangup();
		}
	}

}
